<?php
	$path = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);
	
	if($_REQUEST['submit']) {
		$number_of_days = 30 ;
		$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days;	
		$username = $_REQUEST['username'];
		$password = $_REQUEST['password'];
		setcookie( "username", $username, $date_of_expiry, "/" );
		setcookie( "password", $password, $date_of_expiry, "/" );
		header('Location: '.$path.'/index.php');
		exit;
	}
	
	if($_REQUEST['logout'] == 1) {
		$date_of_expiry = time() - 60;
		setcookie( "username", "", $date_of_expiry, "/" );
		setcookie( "password", "", $date_of_expiry, "/" );
		header('Location: '.$path.'/index.php');
		exit;				
	}	
	
	if($_COOKIE['username'] != '' && $_COOKIE['password'] != '') {
		header('Location: '.$path.'/index.php');
		exit;
	}	
?>
<?php include('header.php') ?>
<h2>Login Plurk</h2>
<form method="post">
  <label>
  Username:
  <input type="text" name="username" id="username" />
  </label>
  <br />
  <label>Password:
  <input type="password" name="password" id="password" />
  </label> 
  <br /> 
  <input type="submit" name="submit" id="button" value="Submit" />
</form>
<p>YoHang Plurk Client provides a wrapper around the Plurk API. We don't store any usernames or passwords. The only data we keep about you are your   preferences so that you can maintain your settings no matter what computer/device you are browsing from! </p>
<?php include('footer.php') ?>